﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Meebey.SmartIrc4net;

namespace BattleMaster_IRCbot
{
    class Program
    {
        // Instantiate high-level classes
        public static IrcClient irc = new IrcClient();
        public static Game gameEnvironment;
        public static string activeDirectory = Directory.GetCurrentDirectory();

        static void Main(string[] args)
        {
            //Perform initialization.
            Thread.CurrentThread.Name = "Main";
            gameEnvironment = new Game();
            IRChandler IRC_Handler = new IRChandler(irc, gameEnvironment);
            gameEnvironment.ircHandler = IRC_Handler; // Have to pass a refrence to the IRC handler back to gameEnvironment

            //Start threads for input processing.
            Thread ConsoleThread = new Thread(new ThreadStart(ListenForConsole));
            ConsoleThread.Start();

            Thread IRCthread = new Thread(new ThreadStart(irc.Listen));
            IRCthread.Start();
        }

        static void ListenForConsole()
        {
            while (true)
            {
                //Read console input then create strings to represent the command and arguments
                string cmdBuffer = System.Console.ReadLine();
                string output = "";
                output = gameEnvironment.ProcessInput("console", cmdBuffer);
                if (output != "") System.Console.WriteLine(output);
            }
        }

        public static void Exit()
        {
            System.Console.WriteLine("Exiting...");
            System.Environment.Exit(0);
        }
    }
}
